package com.wtwd.device.service.impl;

import com.wtwd.device.constant.Constants;
import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.entity.SysRole;
import com.wtwd.device.model.entity.SysUser;
import com.wtwd.device.model.vo.RespEntity;
import com.wtwd.device.service.AuthenticationService;
import com.wtwd.device.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author mjy
 * @date 2021/08/16
 * @description
 */
@Service
public class AuthenticationServiceImpl implements AuthenticationService {

    @Autowired
    private SysRoleService sysRoleService;

    @Override
    public RespEntity checkAdmin(SysUser sysUser) {
        if (sysUser == null) {
            return new RespEntity(RespCode.TOKEN_UNAUTHORIZED);
        } else {
            SysRole sysRole = sysRoleService.getSysRoleByRoleId(sysUser.getRoleId());
            if (!sysRole.getRoleType().equals(Constants.SYS_USER_ROLE_TYPE_ADMIN)) {
                return new RespEntity(RespCode.NO_PERMISSION);
            }
        }
        return null;
    }
}
